# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Uwe Koloska <kolewu@koloro.de>
# Contributor: EpocSquadron <crimsonmage a gmail>

pkgname=libreoffice-extension-writer2latex
_javaname=writer2latex
_exts=(writer2latex writer2xhtml w2lconfig)
pkgver=1.6.1
pkgrel=2
pkgdesc="A java program and collection of LibreOffice extensions for converting to and working with LaTeX in LibreOffice"
arch=(any)
url="https://writer2latex.sourceforge.net"
license=(LGPL)
depends=(libreoffice java-runtime-headless)
_srcname=${_javaname}${pkgver//\./}
source=("https://sourceforge.net/projects/writer2latex/files/writer2latex/Writer2LaTeX%20${pkgver%.*}/${_srcname}.zip"
        'writer2latex.sh')
sha256sums=('f7ca16126083b5d732a4ff17b68b5878fbbe1d972fc9cabba8d54dfcecdb88c9'
            '75eabf5247a0ba362d6eaabf78da01e399a6422d8435d03fff8ac12c8858fdec')

build() {
    cd ${_javaname}16/doc
    libreoffice --headless --convert-to pdf user-manual.odt
}

package() {
    cd ${_javaname}16

    #Install the extensions
    for _ext in "${_exts[@]}"; do
	install -dm755  "$pkgdir/usr/lib/libreoffice/share/extensions/$_ext"
	bsdtar -xf "$_ext.oxt" -C "$pkgdir/usr/lib/libreoffice/share/extensions/$_ext"
    done
    
    #Install the java converter
    install -D -m644 "$_javaname.jar" "$pkgdir/usr/share/java/$_javaname/$_javaname.jar"
    
    #Install shell script to execute java program
    install -D -m755 "$srcdir/$_javaname.sh" "$pkgdir/usr/bin/$_javaname"
    
    #Install documentation
    _docpath="$pkgdir/usr/share/doc/$pkgname"
    install -D -m644 Readme.txt "${_docpath}/Readme.txt"
    install -D -m644 changelog.txt "${_docpath}/changelog.txt"
    install -D -m644 History.txt "${_docpath}/History.txt"
    install -D -m644 doc/* "${_docpath}/"
}
